const express = require('express')
const bodyParser = require('body-parser')
const app = express()

//设置允许跨域访问
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  //Access-Control-Allow-Headers 
  res.header('Access-Control-Allow-Headers', 'Content-Type')
  res.header('Access-Control-Allow-Methods', '*')
  res.header('Content-Type', 'application/json;charset=utf-8')
  next()
})

// const router = require('./router/router')
const router = require('./router/roter_v2')


/** 配置中间件 */
app.use(bodyParser.urlencoded({ extended : false }))
app.use(bodyParser.json())

app.use(router)

app.listen(3000, '127.0.0.2', () => {
  console.log('your server is running....')
})
